﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SMS.Common.Silverlight;
using SMS.Controls.AuthenticationSVC;

using SMS.Entities;
using System.Collections.ObjectModel;
using SMS.Controls.TrackingSVC;

namespace SMS.Model
{
    public class TrackingPageModel
    {
        ServiceProxy<TrackingServiceClient> proxy = null;
        public event Action<ObservableCollection<SaleHistory>> SaleHistoryListCompleted;
        public event Action<ObservableCollection<ClsSaleDetail>> SaleDetailListCompleted;
        public TrackingPageModel()
        {
            proxy = new ServiceProxy<TrackingServiceClient>("Service/TrackingService.svc");
            proxy.Client.LoadSaleHistoryListCompleted += new EventHandler<LoadSaleHistoryListCompletedEventArgs>(Client_LoadSaleHistoryListCompleted);
            proxy.Client.LoadSaleDetailListCompleted += new EventHandler<LoadSaleDetailListCompletedEventArgs>(Client_LoadSaleDetailListCompleted);
        }

        void Client_LoadSaleDetailListCompleted(object sender, LoadSaleDetailListCompletedEventArgs e)
        {
            if (SaleDetailListCompleted != null)
                SaleDetailListCompleted(e.Result);
        }

        void Client_LoadSaleHistoryListCompleted(object sender, LoadSaleHistoryListCompletedEventArgs e)
          {
            if(SaleHistoryListCompleted!=null)
                SaleHistoryListCompleted(e.Result);
            
        }

        public void GetSalesHistory(string userName,int SaleID)
        {
            proxy.Client.LoadSaleHistoryListAsync(userName,SaleID);
        }

        public void GetSalesDetail(string userName,int saleid)
        {
            proxy.Client.LoadSaleDetailListAsync(userName, saleid);
        }
    }
}
